<?php
/**
 * 政策类型
 */
namespace app\model;

use think\Model;

class PolicyTypeModel extends Model
{
	protected $name = 'policy_type';
	
	// 设置当前模型的数据库连接
	protected $connection ='db_yunduan';
	/**
	 * 政策类型列表
	 *
	 */
	public function GetList($where='1=1'){
		$PolicyTypeModel=new PolicyTypeModel;
		$result=$PolicyTypeModel->field('id,type_name')->where($where)->order('sort desc')->paginate();
		return $result;
	}
	/**
	 * 政策类型一维列表
	 *
	 */
	public function GetListColumn($where='1=1'){
		$PolicyTypeModel=new PolicyTypeModel;
		$result=$PolicyTypeModel->where($where)->column('type_name','id');
		return $result;
	}
	/**
	 * 政策类型详情
	 *
	 */
	public function detail($id){
		$PolicyTypeModel = PolicyTypeModel::find($id);
		return $PolicyTypeModel;
	}
	/**
	 * 添加
	 *
	 */
	public function AddData($param){
		$PolicyTypeModel = new PolicyTypeModel;
		$param['createtime']=time();
		$param['updatetime']=time();
		
		$field=['title','desc','img','url','froms','content','createtime','updatetime','role_id'];
		$PolicyTypeModel->allowField($field)->save($param);
		return $PolicyTypeModel->id;
	}
	/**
	 * 编辑
	 *
	 */
	public function EditData($param,$id){
		$PolicyTypeModel = PolicyTypeModel::find($id);
		$param['updatetime']=time();
		
		$field=['title','desc','img','url','froms','content','updatetime'];
		
		$PolicyTypeModel->allowField( $field)->save($param);
		return $id;
	}
	/**
	 * 修改禁用状态
	 *
	 */
	public function UpdateStatus($id){
		$PolicyTypeModel = PolicyTypeModel::find($id);
		$PolicyTypeModel->status=$PolicyTypeModel->status==1?0:1;
		$PolicyTypeModel->save();
		return true;
	}
	/**
	 * 删除
	 *
	 */
	public function Del($param){
		$update=[];
		foreach($param as $val){
			$update[]=['id'=>$val,'status'=>-1,'deletetime'=>time()];
		}
		if(!empty($update)){
			$PolicyTypeModel = new PolicyTypeModel;
			$PolicyTypeModel->saveAll($update);
		}
		return true;
	}
}